package com.example.demo.service;

import com.example.demo.entity.TableProduct;
import com.example.demo.entity.Users;
import com.example.demo.entity.UsersDto;
import com.example.demo.mapper.TableProductMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.utils.AppDataUtil;
import com.example.demo.utils.HttpClientUtil;
import com.example.demo.utils.PageDataList;
import com.example.demo.utils.ResultUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;


@Service
public class ProductService {

    @Autowired
    private TableProductMapper tableProductMapper;



   public  PageDataList<TableProduct> getList(TableProduct usersDto){
       List<TableProduct> resultList = new ArrayList<>();
       PageHelper.startPage(usersDto.getPageNumber(), usersDto.getPageSize());
        List<TableProduct> dbResult = tableProductMapper.getList(usersDto);

        Page<TableProduct> dbResultPage = (Page<TableProduct>) dbResult;
        for (TableProduct dbItem : dbResultPage.getResult()) {
            resultList.add(dbItem);
        }

        PageDataList<TableProduct> pageDataList = new PageDataList<>(dbResultPage.getTotal(),
                dbResultPage.getPages(),
                dbResultPage.getPageNum(), dbResultPage.getPageSize());
        pageDataList.setList(resultList);
        return pageDataList;

    }




}
